#include <iostream>
#include <string>
#include "../Headers/types.h"

#include "tui.usermanager.h"
#include "tui.utils.h"

/**
 *  Change full name
 */
void tuiUMChangeFullName(TOB::Shell &shell, std::string &username, std::string &fullname) {
  if(username.size() == 0) return shell.wrongParam("Username");
  if(fullname.size() == 0) return shell.wrongParam("Full name");
}


/**
 *  Change password
 */
void tuiUMChangePassword(TOB::Shell &shell, std::string &username) {
  if(username.size() == 0) return shell.wrongParam("Username");
  std::string password;
  shell.getPassword(password);
}


/**
 *  Add user
 */
void tuiUMAddUser(TOB::Shell &shell, std::string &username, std::string &fullname) {
  if(username.size() == 0) return shell.wrongParam("Username");
  if(fullname.size() == 0) return shell.wrongParam("Full name");
  std::string password;
  shell.getPassword(password);
}


/**
 *  Delete user
 */
void tuiUMDeleteUser(TOB::Shell &shell, std::string &username) {
  if(username.size() == 0) return shell.wrongParam("Username");
}


/**
 *  Change role
 */
void tuiUMChangeRole(TOB::Shell &shell, std::string &username, uint32 role) {
  if(username.size() == 0) return shell.wrongParam("Username");
}


/**
 *  Change rights
 */
void tuiUMChangeRights(TOB::Shell &shell, std::string &username, uint32 rights) {
  if(username.size() == 0) return shell.wrongParam("Username");
}


/**
 *  Entry point
 */
void tuiUserManager(TOB::Shell &shell, std::stringstream &stream) {
  uint32 data;
  std::string action, uname = "";
  stream >> action;  

  if(action == "change-fullname") {
    action = "";
    stream >> uname;
    readStreamToEnd(stream, action);
    tuiUMChangeFullName(shell, uname, action);

  } else if(action == "change-password") {
    stream >> uname;
    tuiUMChangePassword(shell, uname);
  
  } else if(action == "add-user") {
    action = "";
    stream >> uname;
    readStreamToEnd(stream, action);
    tuiUMAddUser(shell, uname, action);

  } else if(action == "delete-user") {
    stream >> uname;
    tuiUMDeleteUser(shell, uname);

  } else if(action == "change-role") {
    stream >> uname;
    stream >> data;
    tuiUMChangeRole(shell, uname, data);
  
  } else if(action == "change-rights") {
    stream >> uname;
    stream >> data;
    tuiUMChangeRights(shell, uname, data);
  
  } else {
    shell.write("Using: {change-fullname|change-password|change-role|change-rights|add-user|delete-user} username [param]").writeLine();
  }
}
